package com.bishi.demo.service;

import com.bishi.demo.pojo.DisCount;
import com.bishi.demo.pojo.Fruit;
import com.bishi.demo.pojo.FruitEnum;

import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;

public class DisCountService {

    public static Double Discount(List<Fruit> fruitList, DisCount disCount) {
        AtomicReference<Double> price = new AtomicReference<>(0.0d);
        fruitList.forEach(fruit -> {
            if (disCount != null && fruit.getFruit_name().equals(disCount.getDiscount_fruit())) {
                price.set(price.get() + fruit.getFruit_unit() * fruit.getFruit_weight() * disCount.getDis_prop());
            } else {
                price.set(price.get() + fruit.getFruit_unit() * fruit.getFruit_weight());
            }
        });
        return price.get();
    }
}
